using Ease.EaseDialog.Editor;
using Ease.EaseDialog.Runtime;
using Ease.EaseDialog.Runtime.Data;
using Ease.EaseDialog.Scripts.Editor.Node;
using Ease.EaseNode.Editor.NodeView;
using UnityEditor;

public class DialogEW : BaseEaseEditorWindow<DialogChartView, DialogSoInspectorView>
{
    protected override string VisualTree => "Assets/Ease/EaseDialog/Scripts/Editor/DialogEW.uxml";
    protected override string StyleSheet => "Assets/Ease/EaseDialog/Scripts/Editor/DialogEW.uss";

    private UnityEngine.Object Current { get; set; }

    protected override void OnPrepareData()
    {
        //Data2Node配置表
        dicData2Node.Add(typeof(DialogData), typeof(DialogNode));
        dicData2Node.Add(typeof(DialogData2), typeof(DialogNode2));

        //数据管理器.
        DataManager = (Selection.activeObject as DialogDataSo)?.NodeDataManager;
        Current = Selection.activeObject;
    }

    protected override void OnCreateGUIOther()
    {
        DialogSoInspectorView dialogSoInspectorView = UpdateSelection as DialogSoInspectorView;
        dialogSoInspectorView?.OnEnable();
    }

    private void OnSelectionChange()
    {
        if (Selection.activeObject != Current)
        {
            DialogDataSo so = (Selection.activeObject as DialogDataSo);
            if (so != null)
            {
                Current = Selection.activeObject;
                DialogDataSo.Instance = so;
                DataManager = so.NodeDataManager;
                UpdateSelection.OnUpdateSelection(null);
                EaseChartView.Reset();
            }
        }
    }
}